#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

void handler(int sig)
{
	pid_t id;
	while((id=waitpid(-1,NULL,WNOHANG))>0){
		printf("wait child success:%d\n",id);
	}
}
int main()
{
	pid_t cid;
	if(cid=fork()==0){
		int i=10;
		while(i){
			printf("child :%d\n",getpid());
			i--;
		}
	}
	else if(cid<0){
		exit(1);
	}else{
		struct sigaction act,oact;
		act.sa_flags=0;
		act.sa_handler=handler;
		sigemptyset(&act.sa_mask);
		sigaction(SIGCHLD,&act,&oact);
		while(1);
	}	
}



